package org.springcloud.wisdom.springcloud_03_freshman.admin.controller;

import org.springcloud.wisdom.springcloud_03_freshman.admin.service.AdminFreshmanService;
import org.springcloud.wisdom.springcloud_03_freshman.common.bean.ResponseData;
import org.springcloud.wisdom.springcloud_03_freshman.common.controller.BaseController;
import org.springcloud.wisdom.springcloud_03_freshman.student.service.FreshmanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/admin/freshman")
public class AdminFreshmanController extends BaseController {
@Autowired
    AdminFreshmanService adminFreshmanService;

    /**
     * 获取所有的新生
     * @param pageNum 页码数
     * @param pageSize 每页记录数
     * @param sname 姓名
     * @param dept 院系
     * @param sid 学号
     * @return
     */
    @GetMapping("/page")
    public ResponseData<Object> fershmanPage(
            @RequestParam("pageNum") int pageNum,
            @RequestParam("pageSize")int pageSize,
            @RequestParam(value = "sname",required = false)String sname,
            @RequestParam(value = "dept",required = false)Integer dept,
            @RequestParam(value = "sid",required = false) String sid
    ){
        return  returnObject(adminFreshmanService.getFreshmanPage(pageNum, pageSize, sname, dept, sid));
    }

    /**
     * 根据sid删除新生
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public ResponseData<Boolean> deleteFreshman(@PathVariable("id") Integer id){
        return returnObject(adminFreshmanService.deleteF(id));
    }

    /**
     * 根据id删除多条
     * @param ids
     * @return
     */
    @DeleteMapping("/dels")
    public  ResponseData<Boolean> dels(@RequestParam("id") List<Integer> ids){
        return  returnBoolean(adminFreshmanService.delIds(ids));
    }
}
